/**
 * @file 场景运行结果网格实现
 *
 * 场景运行结果网格实现
 *
 * @author wq1977@gmail.com
 */

#include "ScenariosResultGrid.h"
#include "ScenariosForm.h"

/**
 * Update Scenarios Result int GUI
 * 
*/
void ScenariosResultGrid::UpdateState(){
    ScenariosForm *p=(ScenariosForm *)GetParent()->GetParent()->GetParent();
    if (p){
	wxTimeSpan t=wxDateTime::UNow()-p->ScenarioStartAt;
	BeginBatch();	  
	SetCellValue(0,0,wxString::Format(wxT("%d"),p->RunningScenariosNum));
	SetCellValue(0,1,wxString::Format(wxT("%d"),p->SuccScenariosNum));
	SetCellValue(0,2,wxString::Format(wxT("%d"),p->FailScenariosNum));
	int totalfinish=p->SuccScenariosNum+p->FailScenariosNum;
	if (totalfinish>0){
	    SetCellValue(0,3,wxString::Format(wxT("%.2f%%"),(double)p->FailScenariosNum*100/totalfinish));
	}
	else{
	    SetCellValue(0,3,wxString::Format(wxT("%d%%"),0));
	}
	SetCellValue(0,4,wxString::Format(wxT("%d"),p->RunningScenariosNum
					  - p->SuccScenariosNum
					  - p->FailScenariosNum));
	int callheavy=-1;
	if (t.GetSeconds()>0){
	    callheavy = p->RunningScenariosNum / t.GetSeconds().ToLong();
	}
	SetCellValue(0,5,wxString::Format(wxT("%d"),callheavy)); //pSc->threadpool->depth()
	if (GetNumberCols()>6){
	    DeleteCols(6,GetNumberCols()-6);
	}
	AppendCols(p->ErrStatistic.size());
	int CurCol=6;
	for(StrLongHash::iterator iter = p->ErrStatistic.begin(); iter != p->ErrStatistic.end(); iter++) {
	    SetColLabelValue(CurCol,iter->first);
	    SetCellValue(0,CurCol,wxString::Format(wxT("%ld"),iter->second));
	    SetReadOnly(0,CurCol);
	    CurCol++;
	}
	AutoSizeColumns();
	
	EndBatch();
    }
}

ScenariosResultGrid::ScenariosResultGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const long style)
	:wxGrid(parent,id,pos,size,style){
	BeginBatch();
	CreateGrid( 1, 6);
	SetRowLabelSize(0);
	DisableCellEditControl();
	SetDefaultColSize(30);
	SetDefaultRowSize(30);
	SetDefaultCellAlignment(wxALIGN_CENTRE,wxALIGN_CENTRE);
	SetColLabelAlignment(wxALIGN_CENTRE,wxALIGN_CENTRE);
	SetColLabelSize(20);
	SetColLabelValue(0,_("Total"));
	SetColLabelValue(1,_("Succ"));
	SetColLabelValue(2,_("Fail"));
	SetColLabelValue(3,_("Fail Rate"));
	SetColLabelValue(4,_("InProgress"));
	SetColLabelValue(5,_("Call Heavy"));
	AutoSizeColumns();
	for (int i=0;i<5;i++){
		SetReadOnly(0,i);
	}
	EndBatch();
}

ScenariosResultGrid::~ScenariosResultGrid(){
}


